package com.mc2.docapp.disabilityassessmenttool.LowerLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_llmp_ankleFoot extends RealmObject {
    private LLCustDataType dorsiflexion = new LLCustDataType();
    private LLCustDataType plantar_flexion = new LLCustDataType();
    private LLCustDataType inversion = new LLCustDataType();
    private LLCustDataType eversion = new LLCustDataType();
    private LLInnerCalculations inner_calculations = new LLInnerCalculations();

    public void calc(C_llmp_ankleFoot c_llmp_ankleFoot) {
        double a = c_llmp_ankleFoot.getDorsiflexion().getActual_right();
        double b = c_llmp_ankleFoot.getPlantar_flexion().getActual_right();
        double c = c_llmp_ankleFoot.getInversion().getActual_right();
        double d = c_llmp_ankleFoot.getEversion().getActual_right();

        double pa = perc(a, c_llmp_ankleFoot.getDorsiflexion().getNormal());
        double pb = perc(b, c_llmp_ankleFoot.getPlantar_flexion().getNormal());
        double pc = perc(c, c_llmp_ankleFoot.getInversion().getNormal());
        double pd = perc(d, c_llmp_ankleFoot.getEversion().getNormal());


        double x = (pa + pb + pc + pd) / 4.0;
        c_llmp_ankleFoot.getDorsiflexion().setPerc_loss_right(pa);
        c_llmp_ankleFoot.getPlantar_flexion().setPerc_loss_right(pb);
        c_llmp_ankleFoot.getInversion().setPerc_loss_right(pc);
        c_llmp_ankleFoot.getEversion().setPerc_loss_right(pd);


        a = c_llmp_ankleFoot.getDorsiflexion().getActual_left();
        b = c_llmp_ankleFoot.getPlantar_flexion().getActual_left();
        c = c_llmp_ankleFoot.getInversion().getActual_left();
        d = c_llmp_ankleFoot.getEversion().getActual_left();

        pa = perc(a, c_llmp_ankleFoot.getDorsiflexion().getNormal());
        pb = perc(b, c_llmp_ankleFoot.getPlantar_flexion().getNormal());
        pc = perc(c, c_llmp_ankleFoot.getInversion().getNormal());
        pd = perc(d, c_llmp_ankleFoot.getEversion().getNormal());
        double y = (pa + pb + pc + pd) / 4.0;

        c_llmp_ankleFoot.getDorsiflexion().setActual_left(pa);
        c_llmp_ankleFoot.getPlantar_flexion().setActual_left(pb);
        c_llmp_ankleFoot.getInversion().setActual_left(pc);
        c_llmp_ankleFoot.getEversion().setActual_left(pd);

        c_llmp_ankleFoot.setInner_calculations(new LLInnerCalculations(
                x,
                y,
                x * 0.3,
                y * 0.3
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
